<?php

namespace App\Http\Controllers;

use App\Models\FeedBack;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests\FeedBackRequest;
use Auth;
class FeedBackController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

	public function index(FeedBack $feed_back)
	{
        $user = Auth::user();
        $feed_backs = FeedBack::with('user')->paginate();
        $this->authorize('destroy', $feed_back);

		return view('feed_backs.index', compact('feed_backs', 'user'));
	}

	public function store(FeedBackRequest $request)
	{
        $data = $request->all();
        $data['user_id'] = $request->user()->id;
		$feed_back = FeedBack::create($data);
		return redirect()->route('notices.index')->with('success', '您的意见已经提交.');
	}

	public function destroy(FeedBack $feed_back)
	{
		$this->authorize('destroy', $feed_back);
		$feed_back->delete();

		return redirect()->route('feed_backs.index')->with('success', '删除成功.');
	}
}
